﻿package mortal.game.view.guildNew.mercenary
{
    import Message.Public.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.guildNew.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewMercenaryProcessor extends Object
    {
        private var _view:IView;
        public static var oneDayTimes:int = 5;
        public static var onePersonTimes:int = 1;
        public static var canRentCopy:Boolean = false;

        public function GuildNewMercenaryProcessor()
        {
            this.initServer();
            return;
        }// end function

        public function initView(param1:IView) : void
        {
            this._view = param1;
            return;
        }// end function

        public function initServer() : void
        {
            EventUtil.addSelfEvent(EventName.GuildNewMercenaryOpen, this.onOpenHd, true);
            EventUtil.addNetEvent(ServerCommand.GuildNewMercenaryUpdateMoney, this.updateCanGetGoin, true);
            return;
        }// end function

        public function onViewShow() : void
        {
            this.addEvs(true);
            return;
        }// end function

        public function onViewHide() : void
        {
            this.addEvs(false);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewMercenaryGetInfo, this.onReqListInfo, param1);
            EventUtil.addNetEvent(ServerCommand.GuildNewGetMercenaryInfoBack, this.listBack, param1);
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewMercenaryGetOne, this.getOnePerson, param1);
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewMercenaryAddIn, this.onSelfAddIn, param1);
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewMercenaryGetRw, this.onGetRw, param1);
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewMercenaryUpdate, this.listBack, param1);
            return;
        }// end function

        private function onReqListInfo(event:DataEvent) : void
        {
            GameProxy.guild.getGuildMercenaryInfo(Cache.instance.guild.selfGuildInfo.guildID);
            return;
        }// end function

        private function listBack(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewMercenaryPanel;
            if (_loc_2)
            {
                _loc_2.updateList();
            }
            return;
        }// end function

        private function onOpenHd(event:DataEvent) : void
        {
            if (!LevelCheckUtil.isLevelEnougth(LevelCheckUtil.mercenary))
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(71546, LevelCheckUtil.getLevel(LevelCheckUtil.mercenary)));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpen, GuildNewModule.Mercenary));
            return;
        }// end function

        private function updateCanGetGoin(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewMercenaryPanel;
            if (_loc_2)
            {
                _loc_2.updateCanGetGoin();
            }
            return;
        }// end function

        private function getOnePerson(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = event.data as SGuildMercenary;
            if (_loc_2 == null)
            {
                return;
            }
            if (Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoin, _loc_2.money, null, false))
            {
                GameProxy.copy.rentGuildMercenary(_loc_2.playerId, _loc_2.money);
            }
            else
            {
                _loc_3 = _loc_2.money - Cache.instance.role.money.coin;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShowCoinPackWin, _loc_3));
            }
            return;
        }// end function

        private function onSelfAddIn(event:DataEvent) : void
        {
            var _loc_2:* = event.data as int;
            GameProxy.guild.registerMyMercenary(_loc_2);
            return;
        }// end function

        private function onGetRw(event:DataEvent) : void
        {
            GameProxy.player.getMercenaryReward();
            return;
        }// end function

    }
}
